package org.wlgzs.office_exam_student.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.wlgzs.office_exam_student.dao.BaseDao;
import org.wlgzs.office_exam_student.entity.ChoiceQuestion;
import org.wlgzs.office_exam_student.entity.ExamQuestion;

/**
*@author song(mejeesong@qq.com)
*2018年1月30日
*
*/
public class ChoiceQuestionService extends BaseDao<ChoiceQuestion> {
	
	public List<ChoiceQuestion> choiceQuestions(int schoolId, int questionNumber, String grade) {

		List<ChoiceQuestion> choiceQuestions = exec(qr -> {
			try {
				return qr.query(
						"SELECT * FROM   tb_choice_question   where  school_id = ? and  grade = ? ORDER BY RAND() LIMIT ?",
						BEAN_LIST_HANDLER, schoolId, grade, questionNumber);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return null;
		});
		return choiceQuestions;
	}

	public ChoiceQuestion choiceQuestion(int questionId) {

		ChoiceQuestion choiceQuestion = exec(qr -> {
			try {
				return qr.query(
						"SELECT * FROM   tb_choice_question  where  id = ?",
						BEAN_HANDLER, questionId);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return null;
		});
		return choiceQuestion;
	}

	public List<ChoiceQuestion> choiceQuestionsByIds(String ids){

		String sql = "select * from tb_choice_question where id in "+ids;
		logger.debug(sql);
		List<ChoiceQuestion> choiceQuestions = exec(qr -> {
			try {
				return qr.query(sql, BEAN_LIST_HANDLER);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return null;
		});

		return choiceQuestions;
	}
}
